/**
 * Created by zhu on 2015/1/30.
 */
$(function(){
    var myhregf = window.location.href;
    var count = myhregf.split('/').length;
    var id = myhregf.split('/')[count-1];
    $.get(contextPath + "/goods/isCollection/"+id,function(data){
        iscollection(data)
    });
    $('#collection').on('click', function () {
        $.get(contextPath + "/goods/collection/"+id,function(data){
            collection(data)
        });

    });

});

function collection(data){
    data = jQuery.parseJSON(data);

    if(data.status == 0){
        $('#collection_text').text("收藏")
        $('.icon-star').css('color',"#ccc")
    }else if(data.status == 2){
        $('#collection_text').text("已收藏")
        $('.icon-star').css('color',"red")
    }else{
        alert("服务器出错");
    }
}

function iscollection(data){
    data = jQuery.parseJSON(data);
    if(data.status == 0){
        $('#collection_text').text("收藏")
    }else if(data.status == 2){
        $('#collection_text').text("已收藏")
    }else{
        alert("服务器出错");
    }
}